﻿using System;

namespace BattleforgeAssault
{
    public class Effect : GameObject, IComparable<Effect>
    {
        #region Properties

        private string _trigger = "None";
        /// <summary>
        /// A phase or event name with Pre or Post (ex. PreQuestPhase, PostCardLeftPlay) used by the controller to call this effect's Apply.
        /// Modifiers should use this to store the name of the stat they wish to modify.
        /// </summary>
        public string Trigger { get { return _trigger; } set { _trigger = value; RaisePropertyChanged("Trigger"); } }

        private GameObject _source = null;
        /// <summary>
        /// Where this effect came from.
        /// </summary>
        public GameObject Source { get { return _source; } set { _source = value; RaisePropertyChanged("Source"); } }

        private int _priority = 0; // TODO: add to priority based on type
        /// <summary>
        /// The order to apply this effect when multiple effects use the same trigger.
        /// </summary>
        public int Priority { get { return _priority; } set { _priority = value; RaisePropertyChanged("Priority"); } }

        #endregion Properties

        /// <summary>
        /// Determine whether to apply the effect.
        /// </summary>
        /// <param name="sender">The cause of the effect. 
        /// For Actions, this will be the card with the action on it. 
        /// For modifiers, it will be the card being modified.</param>
        /// <returns>True if the effect should apply based on the game state.</returns>
        public virtual bool Applicable(GameObject sender)
        {
            return false;
        }

        /// <summary>
        /// Apply the effect. Usually only called after Applicable is called but it might be a good idea to check it in Apply anyway.
        /// </summary>
        /// <param name="sender">The cause of the effect.</param>
        public virtual void Apply(GameObject sender)
        {
        }

        #region Helper Methods

        public override string ToString()
        {
            if (Source is Card) { return ((Card)Source).Title + " Effect"; }
            else { return "Unknown Effect"; }
        }

        public int CompareTo(Effect other)
        {
            return this.Priority.CompareTo(other.Priority);
        }

        #endregion Helper Methods
    } // Class
} // Namespace
